package com.lixin.admin.server.controller;

import com.lixin.admin.server.service.AdminService;
import com.lixin.admin.server.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "管理员相关接口")
public class AdminController {
    @Resource
    private AdminService adminService;

    @PostMapping("/admin")
    @ApiOperation("管理员列表")
    public CommonResponseVO<List<AdminVO>> list(@ApiParam("过滤条件") @RequestBody AdminSearchVO adminSearchVO) {
        //List<AdminVO> adminList = adminService.getList(adminSearchVO);
        return new CommonResponseVO<>(ResponseCode.SUCCESS, adminService.getList(adminSearchVO));
    }

    @PostMapping("/admin/create")
    @ApiOperation("新增管理员")
    public CommonResponseVO<Boolean> create(@ApiParam("新增管理员信息") @RequestBody AdminCreateVO adminCreateVO) {
        boolean res = adminService.create(adminCreateVO);
        if (res) {
            return new CommonResponseVO<>(ResponseCode.SUCCESS, res);
        } else {
            return new CommonResponseVO<>(ResponseCode.FAIL, res);
        }
    }

    @PutMapping("/admin/modify")
    @ApiOperation("修改管理员")
    public CommonResponseVO<Boolean> modify(@ApiParam("修改管理员信息") @RequestBody AdminUpdateVO adminUpdateVO) {
        boolean res = adminService.modify(adminUpdateVO);
        if (res) {
            return new CommonResponseVO<>(ResponseCode.SUCCESS, res);
        } else {
            return new CommonResponseVO<>(ResponseCode.FAIL, res);
        }
    }

    @DeleteMapping("/admin/del")
    @ApiOperation("删除多个管理员")
    public CommonResponseVO<Boolean> del(@ApiParam("删除管理员ID") @RequestBody AdminDelVO adminDelVO) {
        boolean res = adminService.del(adminDelVO);
        if (res) {
            return new CommonResponseVO<>(ResponseCode.SUCCESS, res);
        } else {
            return new CommonResponseVO<>(ResponseCode.FAIL, res);
        }
    }
}
